package com.cloudstreamservice8001.controller;

import com.cloudstreamservice8001.common.Result;
import com.cloudstreamservice8001.entity.RouteInfo;
import com.cloudstreamservice8001.entity.RouteProcess;
import com.cloudstreamservice8001.service.RouteProcessService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/routeProcess")
public class RouteProcessController {

    @Resource
    private RouteProcessService routeProcessService;

    /**
     * 获取路线基本列表
     * 分页查询
     *
     * @return
     */
    @GetMapping("/list")
    public Result list(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize,
                       @RequestParam(value = "deliveryId", required = false) Long deliveryId, @RequestParam(value = "routeId",  required = false) Long routeId) {
        return Result.success(routeProcessService.getRouteProcess(pageNum, pageSize, deliveryId, routeId));
    }

    /**
     * 创建/更新路线信息
     *
     * @param
     * @return
     */
    @PostMapping(value = {"/create", "/update"})
    public Result createOrUpdate(@RequestBody RouteProcess routeProcess) {
        if (routeProcess.getId() == null) {
            routeProcessService.create(routeProcess);
            return Result.success("创建成功");
        }
        routeProcessService.updates(routeProcess);
        return Result.success("更新成功");
    }

    /**
     * 删除配送信息
     */
    @PostMapping("/delete")
    public Result delete(@RequestBody RouteProcess routeProcess) {
        boolean delete = routeProcessService.removeByCode(routeProcess);
        return delete ? Result.success("删除成功") : Result.error("删除失败");
    }


}
